<template>
  <div class="shoplist_container">
    <ul v-for="(item, index) in shoplist" :key="index">
      <router-link :to="'/shop/' + item.id" tag="li" class="shop_li">
        <section>
          <img :src="uploads + item.image" class="shop_img" />
        </section>
        <hgroup class="shop_right">
          <header class="shop_detail_header">
            <van-tag type="warning">品牌</van-tag>
            <h4>{{ item.name }}</h4>
          </header>
          <h5 class="rating_order_num">
            <section class="rating_order_num_left">
              <section class="rating_section">
                <van-rate
                  :value="item.rating"
                  allow-half
                  :size="18"
                  color="#ffd21e"
                  void-icon="star"
                  void-color="#eee"
                />
                <span class="rating_num">{{ item.rating }}</span>
              </section>
              <section class="order_section">
                月售{{ item.recent_order_num }}单
              </section>
            </section>
            <section class="rating_order_num_right">
              <span class="delivery_style delivery_left">吃了吗专送</span>
              <span class="delivery_style delivery_right">准时达</span>
            </section>
          </h5>
          <h5 class="fee_distance">
            <p class="fee">
              {{ item.minimum_order_amount }}元起送
              <span class="segmentation">/</span>
              配送费约{{ item.delivery_fee }}元
            </p>
            <p class="distance_time">
              <span>距离{{ item.distance }}公里</span>
              <span class="segmentation">/</span>
              <span class="order_time">{{ item.order_lead_time }}分钟</span>
            </p>
          </h5>
        </hgroup>
      </router-link>
    </ul>
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";

export default {
  name: "shoplist",
  data() {
    return {
      shoplist: [],
    };
  },
  computed: {
    ...mapState({
      uploads: (state) => state.uploads,
    }),
  },
  created() {
    axios.get("/api/shop/shoplist").then((response) => {
      this.shoplist = response.data.data;
    });
  },
};
</script>

<style lang="scss" scoped>
$blue: #3190e8;

h5 {
  margin: 0;
}
.shoplist_container {
  margin-bottom: 50px;
  background-color: #fff;
}
.shop_li {
  display: flex;
  padding: 10px 10px;
  border-bottom: 1px solid #f1f1f1;
}
.shop_img {
  display: block;
  margin-right: 10px;
  width: 155px;
  height: 135px;
}
.shop_right {
  flex: auto;
  .shop_detail_header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 50px;
    h4 {
      margin-left: 10px;
    }
  }
  .rating_order_num {
    display: flex;
    justify-content: space-between;
    height: 50px;
    .rating_order_num_left {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .rating_section {
        display: flex;
        .rating_num {
          margin: 0 10px;
          font-size: 16px;
          color: #ff6000;
        }
      }
      .order_section {
        font-size: 12px;
        color: #666;
      }
    }
    .rating_order_num_right {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .delivery_style {
        margin-left: 5px;
        padding: 2px;
        border-radius: 5px;
        border: 1px;
        font-size: 12px;
      }
      .delivery_left {
        border: 1px solid $blue;
        color: #fff;
        background-color: $blue;
      }
      .delivery_right {
        border: 1px solid $blue;
        color: $blue;
      }
    }
  }
  .fee_distance {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: #333;
    .fee {
      font-size: 14px;
      color: #666;
    }
    .distance_time {
      span {
        color: #999;
      }
      .order_time {
        color: $blue;
      }
      .segmentation {
        color: #ccc;
      }
    }
  }
}
</style>